package com.share.device.controller;

import com.share.common.core.web.controller.BaseController;
import com.share.common.core.web.domain.AjaxResult;
import com.share.common.core.web.page.TableDataInfo;
import com.share.device.domain.Personnel;
import com.share.device.service.PersonnelService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 人员管理接口
 * 提供人员的增删改查等操作
 */
@RestController
@RequestMapping("personnel")
@Tag(name = "人员接口")
public class PersonnelController extends BaseController {
    @Autowired
    private PersonnelService personnelService;

    /**
     * 查询人员列表
     * @param personnel
     * @return
     */
    @GetMapping("list")
    @Operation(summary = "查询人员列表")
    private TableDataInfo list(Personnel personnel){
        startPage();
        List<Personnel> list = personnelService.personnelList(personnel);
        return getDataTable(list);
    }
    /**
     * 新增人员
     * @param personnel
     * @return
     */
    @PostMapping
    @Operation(summary = "添加人员")
    public AjaxResult add(@RequestBody @Validated Personnel personnel){
        personnel.setCreateTime(new Date());
        return success(personnelService.save(personnel));
    }
    /**
     * 修改人员
     * @param personnel
     * @return
     */
    @PutMapping
    @Operation(summary = "修改人员")
    public AjaxResult edit(@RequestBody @Validated Personnel personnel) {
        return success(personnelService.updateById(personnel));
    }
    /**
     * 删除人员
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @Operation(summary = "删除人员")
    public AjaxResult remove(@PathVariable Integer id) {
        return success(personnelService.removeById(id));
    }

    /**
     * 获取人员列表
     * @return
     */
    @GetMapping("/select")
    @Operation(summary = "获取人员下拉框")
    public AjaxResult select() {
        return success(personnelService.list());
    }
}
